//
// Created by 28365 on 2025/3/14.
//

#ifndef ODUPDATERSDK_DEFAULTUPDATERECORDER_H
#define ODUPDATERSDK_DEFAULTUPDATERECORDER_H

#include <mutex>
#include "IUpdateRecorder.h"
#include "obj/File.h"

class DefaultUpdateRecorder : public IUpdateRecorder{

private:

    const string fileName = "version.odu";

    ofstream *outStream{};

    int nowVersion = 0;

    File *versionFile = nullptr;

    const ODUpdater *odUpdater = nullptr;

    void tryFlush();

    time_t lastFlush = 0;

    std::mutex fileMutex;

public:

    DefaultUpdateRecorder();

    UpdateRecord getUpdatedVersion(const ODUpdater &odUpdater) override;

    void useVersion(const ODUpdater *odUpdater, int version) override;

    void addRes(int64_t resId) override;

    void complete() override;

    void closeStream() override;

    bool isUseVersion() override;

    ~DefaultUpdateRecorder() override;

};


#endif //ODUPDATERSDK_DEFAULTUPDATERECORDER_H
